package com.jfinal.ext.util;

import org.jetbrains.annotations.NotNull;

import java.io.File;

/**
 * @author Timor
 * @version 1.0
 * @date 2023/03/16 21:12:38
 */
public class MyFileUtil {

    private MyFileUtil() {}

    public static String getName(@NotNull File file) {
        return getName(file.getName());
    }

    public static String getExtension(@NotNull File file) {
        return getExtension(file.getName());
    }

    private static String getName(@NotNull String fileName) {
        final int dotIndex = fileName.lastIndexOf('.');

        return fileName.substring(0, (dotIndex == -1) ? fileName.length() : dotIndex);
    }

    private static String getExtension(@NotNull String fileName) {
        final int dotIndex = fileName.lastIndexOf('.');

        return (dotIndex == -1) ? "" : fileName.substring(dotIndex + 1);
    }

}
